package com.shop2cn.iapi.couponmanage.testcase;

import java.util.ArrayList;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.couponmanage.parameter.CreateBagBean;
import com.shop2cn.iapi.couponmanage.parameter.CreateCouponBean;
import com.shop2cn.iapi.couponmanage.parameter.GetApplyProductsBean;
import com.shop2cn.iapi.couponmanage.service.CreateBagCall;
import com.shop2cn.iapi.couponmanage.service.CreateCouponCall;
import com.shop2cn.iapi.couponmanage.service.GetApplyProductsCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.CouponShop2cnCallService;
import com.ymttest.business.service.CouponShop2cnMCallService;
import com.ymttest.database.model.CouponShop2cn.couponbatch;
import com.ymttest.database.model.CouponShop2cn.couponusecondition;
import com.ymttest.database.sqlwapper.CouponShop2cn.couponbatchWapper;
import com.ymttest.database.sqlwapper.CouponShop2cn.couponuseconditionWapper;
//import com.ymttest.database.model.YmtCouponProduct;
//import com.ymttest.database.sqlwapper.YmtCouponProductWapper;
/**
*获取优惠券适用商品
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetApplyProducts{
	private static GetApplyProductsBean getapplyproductsBean;
	private static GetApplyProductsCall getapplyproductsCall;
	@BeforeClass 
	public static void setUp() {
		Logger.createResultFile("获取优惠券适用商品");
	}

	@Before
	public void caseUp() {
		getapplyproductsBean=new GetApplyProductsBean();
		getapplyproductsCall=new GetApplyProductsCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getapplyproductsCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetApplyProducts_001() {
		Logger.start(true,"更获取优惠券适用商品");
		try {
			CouponShop2cnMCallService CouponShop2cnMCallService = new CouponShop2cnMCallService();
			CouponShop2cnCallService CouponShop2cnCallService = new CouponShop2cnCallService();
			
			CreateCouponBean createCouponBean = CouponShop2cnMCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			List<String> productIds=new ArrayList(); 
			productIds.add("11");
			productIds.add("22");
			createCouponBean.setProductIds(productIds);
			CreateCouponCall createCouponCall= CouponShop2cnMCallService.createPlatformCoupon(createCouponBean);
			
			couponbatch batch=new couponbatchWapper().selectBybatchCode(createCouponCall.getBatchCode()).get(0);
			getapplyproductsBean.setBatchId(batch.getBatchId());
			
			getapplyproductsCall.setData(getapplyproductsBean);
			getapplyproductsCall.callService();			
			
			Logger.verifyEquals("操作成功！", getapplyproductsCall.getMessage(), "验证返回Message");
			Logger.verifyEquals("0", getapplyproductsCall.getCode(), "验证返回StatusCode");

			List<couponusecondition> products=new couponuseconditionWapper().selectByConditionTypeAndBatchId(batch.getBatchId(),2);
			List<String> returnProducts = getapplyproductsCall.getProductCodes().getProductCodes();
			
			Logger.verifyEquals(returnProducts.size(), products.size(), "验证YmtCouponProduct表生成相应记录数");
			
			for(int i=0;i<products.size();i++)
			{
				Logger.verifyEquals(returnProducts.get(i), products.get(i).getConditionValue(), "验证YmtCouponProduct表productCodes");

			}
		} catch (Exception e) { 
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetApplyProducts_002() {
		Logger.start(true,"BatchId空");
		try {
			getapplyproductsCall.setData(getapplyproductsBean);
			getapplyproductsCall.callService();			
			
			Logger.verifyEquals("操作成功！", getapplyproductsCall.getMessage(), "验证返回Message");
			Logger.verifyEquals("0", getapplyproductsCall.getCode(), "验证返回StatusCode");
		
			List<String> returnProducts = getapplyproductsCall.getProductCodes().getProductCodes();
			
			Logger.verifyEquals(0, returnProducts.size(), "验证YmtCouponProduct表生成相应记录数");
		
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetApplyProducts_003() {
		Logger.start(true,"BatchId不存在");
		try {
			int batchId=1345566767;
			getapplyproductsBean.setBatchId(batchId);
			
			getapplyproductsCall.setData(getapplyproductsBean);
			getapplyproductsCall.callService();			
			
			Logger.verifyEquals("操作成功！", getapplyproductsCall.getMessage(), "验证返回Message");
			Logger.verifyEquals("0", getapplyproductsCall.getCode(), "验证返回StatusCode");

			List<String> returnProducts = getapplyproductsCall.getProductCodes().getProductCodes();
					
			Logger.verifyEquals(0, returnProducts.size(), "验证YmtCouponProduct表生成相应记录数");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}